package com.lishao.soccer.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lishao.soccer.bean.entity.SmTeam;
import com.lishao.soccer.bean.entity.TmGameSignup;
import com.lishao.soccer.bean.entity.TmTeamGame;
import com.lishao.soccer.bean.entity.TmTeamOpponent;
import com.lishao.soccer.service.SmTeamService;
import com.lishao.soccer.service.TmTeamGameService;
import com.lishao.system.security.providers.SecurityUser;
import com.lishao.system.utils.ActionUtil;
import com.opensymphony.xwork2.ActionSupport;

public class TeamAction extends ActionSupport {
	SmTeamService smTeamService;
	TmTeamGameService tmTeamGameService;
	
	Long teamId;
	
	public String selectAllTeam() throws Exception{
		List<SmTeam> teamList = smTeamService.selectAllTeam();
		Map resMap = new HashMap();
		resMap.put("teamList", teamList);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String selectTeamById() throws Exception{
		SmTeam smTeam = smTeamService.selectTeamById(teamId);
		Map resMap = new HashMap();
		resMap.put("smTeam", smTeam);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String selectGameByTeam() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List <TmTeamGame> teamGameList = tmTeamGameService.selectByTeam(teamId,secUser.getSmUser().getRowId());
		Map resMap = new HashMap();
		resMap.put("teamGameList", teamGameList);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String selectActiveGameByTeam() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List <TmTeamGame> teamGameList = tmTeamGameService.selectActiveGameByTeam(teamId,secUser.getSmUser().getRowId());
		Map resMap = new HashMap();
		resMap.put("teamGameList", teamGameList);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String selectInActiveGameByTeam() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List <TmTeamGame> teamGameList = tmTeamGameService.selectInActiveGameByTeam(teamId,secUser.getSmUser().getRowId());
		Map resMap = new HashMap();
		resMap.put("teamGameList", teamGameList);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String selectTeamOpponent() throws Exception{
		List<TmTeamOpponent> opponentList = smTeamService.selectTeamOpponent(teamId);
		Map resMap = new HashMap();
		resMap.put("opponentList", opponentList);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	//get set
	public SmTeamService getSmTeamService() {
		return smTeamService;
	}

	public void setSmTeamService(SmTeamService smTeamService) {
		this.smTeamService = smTeamService;
	}

	public TmTeamGameService getTmTeamGameService() {
		return tmTeamGameService;
	}

	public void setTmTeamGameService(TmTeamGameService tmTeamGameService) {
		this.tmTeamGameService = tmTeamGameService;
	}

	public Long getTeamId() {
		return teamId;
	}

	public void setTeamId(Long teamId) {
		this.teamId = teamId;
	}

}
